package com.yimi.yinhepda.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.yimi.yinhepda.R;
import com.yimi.yinhepda.entity.response.BuildPackageDetailResponse;

import java.util.List;

/**
 * 项目名称：YinHePda
 * 创建时间：2017/3/13 13:21
 * 版本号：1.0
 * 功能描述
 *
 * @author 刘宏恩
 */
public class BuildPackageScanAdapter extends BaseAdapter {
  private List<BuildPackageDetailResponse.StockInfo> dataList;
  private Context context;

  public BuildPackageScanAdapter(Context context, List<BuildPackageDetailResponse.StockInfo> dataList) {
    this.context = context;
    this.dataList = dataList;
  }

  @Override public int getCount() {
    return dataList == null ? 0 : dataList.size();
  }

  @Override public Object getItem(int position) {
    return dataList.get(position);
  }

  @Override public long getItemId(int position) {
    return position;
  }

  @Override public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder viewHolder;
    if (convertView == null) {
      viewHolder = new ViewHolder();
      convertView = LayoutInflater.from(context).inflate(R.layout.load_scan_item1, null);
      viewHolder.waybillnum =  convertView.findViewById(R.id.text1);
      viewHolder.count =  convertView.findViewById(R.id.text3);
      viewHolder.scaned =  convertView.findViewById(R.id.text4);
      viewHolder.stock =  convertView.findViewById(R.id.text5);
      convertView.setTag(viewHolder);
    } else {
      viewHolder = (ViewHolder) convertView.getTag();
    }
    //运单号
    viewHolder.waybillnum.setText(dataList.get(position).getWaybillNo());
    //开单数量
    viewHolder.count.setText(dataList.get(position).getSrcPiecesNum() + "");
    //已扫描数量
    viewHolder.scaned.setText(dataList.get(position).getScannedNum() + "");
    //库存数量
    viewHolder.stock.setText(dataList.get(position).getPiecesNum() + "");

    //处理颜色
    int color = dataList.get(position).justColorShow();
    switch (color) {
      case 0:
        convertView.setBackgroundColor(context.getResources().getColor(R.color.red));
        break;
      case 1:
        convertView.setBackgroundColor(context.getResources().getColor(R.color.white));
        break;
      case 2:
        convertView.setBackgroundColor(context.getResources().getColor(R.color.yellow));
        break;
      case 3:
        convertView.setBackgroundColor(context.getResources().getColor(R.color.green));
        break;
      default:
        break;
    }

    return convertView;
  }

  public static class ViewHolder {
    /** 运单号 */
    TextView waybillnum;
    /** 开单 */
    TextView count;
    /** 扫描 */
    TextView scaned;
    /** 库存 */
    TextView stock;
  }
}
